package com.example.myapplication;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;


public class MusicActivity1 extends AppCompatActivity {
    private MyService2 musicPlayerService;
    private boolean isBound = false;

    private ServiceConnection serviceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            MyService2.LocalBinder binder = (MyService2.LocalBinder) service;
            musicPlayerService = binder.getService();
            isBound = true;
        }

        @Override
        public void onServiceDisconnected(ComponentName name) {
            isBound = false;
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.d("crq","2:onCreat");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_music2);
        Intent intent = new Intent(this, MyService2.class);
        bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
    }

    @Override
    protected void onDestroy() {
        Log.d("crq","2:onDestroy");
        super.onDestroy();
        if (isBound) {
            unbindService(serviceConnection);
            isBound = false;
        }
    }

    @Override
    protected void onStart() {
        Log.d("crq","2:onstart");
        super.onStart();
    }

    @Override
    protected void onStop() {
        Log.d("crq","2:onstop");
        super.onStop();
    }

    @Override
    protected void onRestart() {
        Log.d("crq","2:onrestart");
        super.onRestart();
    }

    @Override
    protected void onResume() {
        Log.d("crq","2:onresume");
        super.onResume();
    }

    @Override
    protected void onPause() {
        Log.d("crq","2:onpause");
        super.onPause();
    }
}

